﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using System.Collections.Generic;
using TerminologiaSinacor.Presenter;
using TerminologiaSinacor.Presenter.Interface;

using TerminologiaSinacor.Utility; 

public partial class page_PesquisaFontes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
           Binding();
        }
    }

    private void Binding()
    {
        Responsavel responsavel = new Responsavel();
        TerminologiaSinacor.Utility.BindingUtil.SetDataSource(responsavel.search(), DrpResponsavel, "nome", "nome", "", "[Responsável]");      
        
    }

    protected void BtnPesquisar_Click(object sender, EventArgs e)
    {
        Fontes fontes = this.SetFiltro();
        BindingGrid(fontes);

    }
    
    private void BindingGrid(Fontes fontes)
    {        
        this.GrdFontes.DataSource = fontes.search(fontes);
        this.GrdFontes.DataBind();
    }
    
    private Fontes SetFiltro()
    {
        Fontes myFontes = new Fontes();
        myFontes.Descricao = this.txtDescricao.Text;
        myFontes.Filtro = this.txtFiltro.Text;
        myFontes.Fonte= this.txtFonte.Text;
        myFontes.FonteTipo = this.txtFonteTipo.Text;
        myFontes.Modulo= this.txtModulo.Text;
        myFontes.ModuloPai = this.txtModuloPai.Text;
        myFontes.NomeTermo = this.txtNomeTermo.Text;
        myFontes.Data = this.txtSugestaoData.Text;
        myFontes.TermoSugerido = this.txtTermoSugerido.Text;
        myFontes.TextoAjuda = this.txtTextoAjuda.Text;
        myFontes.Avaliado = this.ChkTermoAvaliado.Checked;
        myFontes.Desprezado = this.ChkTermoDesprezado.Checked;
        myFontes.Responsavel = this.DrpResponsavel.SelectedValue ;

        myFontes.Avaliado = this.ChkTermoAvaliado.Checked;
        myFontes.Desprezado = this.ChkTermoDesprezado.Checked;

        this.ViewState["FontesFiltro"] = myFontes;

        return myFontes;
    }
        
    protected void GrdFontes_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        Fontes fontes = (Fontes)ViewState["FontesFiltro"];
        this.GrdFontes.PageIndex = e.NewPageIndex;
        BindingGrid(fontes);
    }
   
    protected void BtnLimpar_Click(object sender, EventArgs e)
    {
        this.txtDescricao.Text = "";
        this.txtFiltro.Text = "";
        this.txtFonte.Text = "";
        this.txtFonteTipo.Text = "";
        this.txtModulo.Text = "";
        this.txtModuloPai.Text = "";
        this.txtNomeTermo.Text = "";
        this.txtSugestaoData.Text = "";
        this.txtTermoSugerido.Text = "";
        this.txtTextoAjuda.Text = "";
        this.ChkTermoAvaliado.Checked = false;
        this.ChkTermoDesprezado.Checked = false;
        this.DrpResponsavel.SelectedIndex = 0;        
    }
    
    //Evento responsável por alterar a cor da linha do gridview quando passo o mouse por cima
    protected void GrdFontes_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOver", "this.style.backgroundColor='#DAA520'; this.style.cursor='hand';");
            e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor='#ffffff'");
            e.Row.Attributes.Add("onClick", "this.style.backgroundColor='#DAA520'; CarregarCampos(this);");
        }        
    }

    protected void GrdFontes_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        Response.Write("passou");
        e.NewSelectedIndex = GrdFontes.Rows[0].DataItemIndex;  
    }    
}


